package com.github.jdk8Stream.wangzhe;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangcheng03 on 2021-1-25 19:45.
 */
public class Main {
    public static void main(String[] args) {
        learnMap2th();
    }

    private static void learnMap2th() {
        List<HeroPlayerGold> lists = new ArrayList<>();
        lists.add(new HeroPlayerGold("盖伦", "RNG-Letme", 100));
        lists.add(new HeroPlayerGold("诸葛亮", "RNG-Xiaohu", 300));
        lists.add(new HeroPlayerGold("露娜", "RNG-MLXG", 300));
        lists.add(new HeroPlayerGold("狄仁杰", "RNG-UZI", 500));
        lists.add(new HeroPlayerGold("牛头", "RNG-Ming", 500));

        //计算团队经济
        int teamMoney = lists.stream()
                .map(player -> new Gold(player.getGold()))//note1
                .mapToInt(Gold::getGold)
                .reduce(0, (a, b) -> a + b);
        System.out.println("团队经济：" + teamMoney);//1700


        //计算团队经济2
        double teamMoney2 = lists.stream()
                .mapToDouble(HeroPlayerGold::getGold)
                .reduce(0, (a, b) -> a + b);
        System.out.println("团队经济：" + teamMoney2);//1700.0

        //计算两个C位的经济和
        lists.stream()
                .filter(player-> "RNG-Xiaohu".equals(player.getPlayer()) || "RNG-UZI".equals(player.getPlayer()))
                .map(player->new Gold(player.getGold()))
                .mapToInt(Gold::getGold)
                .reduce((a,b)->a+b)
                .ifPresent(System.out::println);//800
    }
}